import pandas as pd

f2 = open('analysis4.txt','w',encoding='utf-8')
f = pd.read_csv('recruit_data.csv')
bigData = f[f['post'].str.contains('大数据')]
citys = list(bigData['city'].value_counts().index)
citys = list(set([i.split('-')[0] for i in citys if len(i.split('-')[0]) < 3]))
a = bigData['min_wages'].str.match(r'^\d+\.\d+$')
b = bigData['max_wages'].str.match(r'^\d+\.\d+$')
for city in citys:
    data = bigData[bigData['city'].str.contains(city).fillna(False)]
    sum = (data['min_wages'].apply(lambda x: float(x))+data['max_wages'].apply(lambda x: float(x)))
    mean = sum/2
    f2.write(city+'  大数据相关岗位的平均工资为:'+'{:.2f}\n'.format(mean.mean()))
f2.close()
